<HTML><HEAD><TITLE>truncate(+Number, -Result)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Arithmetic</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>truncate(+Number, -Result)</H1>
Unifies Result with the closest integer value between 0 and
Number, and of the same numeric type as Number.


<DL>
<DT><EM>Number</EM></DT>
<DD>A number.
</DD>
<DT><EM>Result</EM></DT>
<DD>A variable or number.
</DD>
</DL>
<H2>Description</H2>
   This predicate is used by the ECLiPSe compiler to expand evaluable
   arithmetic expressions.  So the call to truncate(Number, Result) is
   equivalent to
<PRE>
    Result is truncate(Number)
</PRE>
   which should be preferred for portability.
<P>
   This operation works on all numeric types. The result value is the
   closest integral value that lies between 0 and Number (rounding
   towards zero).
<P>
   The result type is the same as the argument type.  To convert the
   type to integer, use integer/2.
<P>
   In coroutining mode, if Number is uninstantiated, the call to truncate/2
   is delayed until this variable is instantiated.
<P>

<H3>Modes and Determinism</H3><UL>
<LI>truncate(+, -) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Number is not instantiated (non-coroutining mode only).
<DT><EM>(24) number expected </EM>
<DD>Number is not of a numeric type.
</DL>
<H2>Examples</H2>
<PRE>
Success:
      X is truncate(1.8).	   (gives Result = 1.0)

      truncate(1.8, 1.0).
      truncate(-1.8, -1.0).
      truncate(5, 5).
      truncate(-6.4, Result).      (gives Result = -6.0)
Fail:
      truncate(1.0, 0.0).
      truncate(0.5, 0).
      truncate(1, r).
Error:
      truncate(A, 6.0).                   (Error 4).
      truncate(4 + 2.3, 6.0).             (Error 24).
</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/arithmetic/is-2.html">is / 2</A>, <A HREF="../../kernel/arithmetic/floor-2.html">floor / 2</A>, <A HREF="../../kernel/arithmetic/ceiling-2.html">ceiling / 2</A>, <A HREF="../../kernel/arithmetic/round-2.html">round / 2</A>, <A HREF="../../kernel/arithmetic/integer-2.html">integer / 2</A>, <A HREF="../../kernel/arithmetic/fix-2.html">fix / 2</A>
</BODY></HTML>
